<template>
  <div>
    <h1>会员等级添加</h1>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td>等级名称</td>
          <td><input type="text" v-model="Lname.name" /></td>
        </tr>
        <tr>
          <td></td>
          <td><input type="button" @click="ok" value="添加" class="btn btn-default"/></td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from "axios";
import { ref, reactive } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();

let Lname = reactive({ name: "" });

const ok = () => {
  //1.判断非空
  if (Lname.name == "") {
    alert("会员等级名称不可为空");
    return;
  }
  
  //发送网络请求
  axios({
    url: "https://localhost:7142/api/Member/LevelAdd",
    method: "POST",
    data: {
      LName: Lname.name,
    },
  })
  .then((res) => {
    console.log(res);
    if (res.data == -1) {
      alert('等级名称不可重复');
      return;
    }
    if(res.data > 0){
      alert('添加成功');
      router.push('/levelList');
    }
  })
  .catch(arr=>{
    console.log(arr);
  })
};
</script>

<style scoped></style>
